In [106]:
import eval_sampling as e
import itn_sampling.functions as sampling

Activation function


In [179]:
reload(e)
s,f,m = e.read_trace('activation_trace', mem_width=16, mem_fraction=12)
p,silent,fire = e.activation_function(0, s, f, m)
fig = e.plot_activation_function(p, figsize=(15,8))
vlines([3.0], ymin=0.0, ymax=1.0)

print "propabilities:"
for k, v in sorted(p.iteritems()):
    print "  %6.2f  :  %1.3f   (%1.3f)" % (k, v, 1./(1.+exp(-k+log(20))))


propabilities:
   -4.00  :  0.001   (0.001)
   -3.50  :  0.002   (0.002)
   -3.00  :  0.002   (0.002)
   -2.50  :  0.004   (0.004)
   -2.00  :  0.007   (0.007)
   -1.50  :  0.012   (0.011)
   -1.00  :  0.020   (0.018)
   -0.50  :  0.028   (0.029)
    0.00  :  0.042   (0.048)
    0.50  :  0.086   (0.076)
    1.00  :  0.122   (0.120)
    1.50  :  0.179   (0.183)
    2.00  :  0.272   (0.270)
    2.50  :  0.380   (0.379)
    3.00  :  0.504   (0.501)
    3.50  :  0.600   (0.623)

In [85]:
reload(e)
fig = e.plot_spikes(s,f)
xlim((0,1000))
fig = e.plot_membrane(m)
ylim((-10,10))


Out[85]:
(-10, 10)

Joint propabilities


In [139]:
states_smpl, fires_smpl, membrane_smpl = e.read_trace('trace', mem_width=16, mem_fraction=10)
#p_jnt = e.count_joint_states(states_smpl)

#fig = figure()
#bar(range(0,16), p_jnt)
#ylabel("p(z)")
#xlabel("z")

#for i in xrange(16):
#    print "%4d : %d" % (i, p_jnt[i])

for neuron_i in xrange(4):
    p,silent,fire = e.activation_function(neuron_i, states_smpl, fires_smpl, membrane_smpl)
    fig = e.plot_activation_function(p, figsize=(10,5), fignum=None)
    print "p = ", p
    print "silent = ", silent
    print "fire = ", fire


---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-139-e98c145e2892> in <module>()
      1 states_smpl, fires_smpl, membrane_smpl = e.read_trace('trace', mem_width=16, mem_fraction=10)
----> 2 p_jnt = e.count_joint_states(states_smpl)
      3 
      4 fig = figure()
      5 bar(range(0,16), p_jnt)

/home/simon/Projects/exploration/ghdl/eval_sampling.py in count_joint_states(states)
     61                 if c: num |= (1 << (K-i-1));
     62 
---> 63             rv[num] += 1
     64 
     65         return rv

IndexError: list index out of range

In [147]:
reload(e)
fig = e.plot_spikes(states_smpl, fires_smpl)
ylim((-0.5,3.5))
#xlim((0, 1000))
fig = e.plot_membrane(membrane_smpl)
#xlim((0, 1000))



In [181]:
reload(e)
states_smpl, fires_smpl, membrane_smpl = e.read_trace('trace', mem_width=16, mem_fraction=10)
W = np.array([[ 0.0,  1.5, 1.0, -1.0],
              [ 1.5,  0.0, 1.0, -1.0],
              [ 1.0,  1.0, 0.0,  0.5],
              [-1.0, -1.0, 0.5,  0.0]])
b = np.array([-1.0, -0.5, -2.0, -1.5])
ext = np.array([0.0, 0.0, 0.0, 0.0])
dist = sampling.BoltzmannDistribution(W, b, ext)

p_jnt_norm = sum(p_jnt)
print p_jnt

states_smpl_ar = array(states_smpl)
print states_smpl_ar
print "KL = ", dist.KL_to_samples(states_smpl_ar)
print dist.p_sample

fig = figure(figsize=(10,6))
bar(range(16), dist.p_ana, width=0.3, label='theory')
#bar(np.array(range(16))+0.3, [float(x)/float(p_jnt_norm) for x in p_jnt], width=0.3, color='red', label='VHDL')
bar(np.array(range(16))+0.3, dist.p_sample, width=0.3, color='red', label='VHDL')
legend(loc='best')


[10346, 4332, 6891, 11373, 1528, 1589, 2608, 11368, 2657, 316, 491, 369, 456, 199, 359, 673]
[[False False False False]
 [ True  True False False]
 [ True  True False False]
 ..., 
 [ True  True  True False]
 [ True  True  True False]
 [ True  True  True False]]
KL =  0.0098145272395
[ 0.15631356  0.05243452  0.02919629  0.01148411  0.13584736  0.00900009
  0.04845648  0.00552606  0.07534875  0.00437404  0.03267033  0.00468005
  0.22340023  0.00543605  0.19508595  0.01074611]
Out[181]:
<matplotlib.legend.Legend at 0xd2447d0>

In [173]:
import copy
fig_joints_2ms = copy.copy(fig)
savefig('joints_cmp.eps', fig_joints_2ms)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-173-2e69a9efe28b> in <module>()
      1 import copy
      2 fig_joints_2ms = copy.copy(fig)
----> 3 savefig('joints_cmp.eps', fig_joints_2ms)

/usr/lib/pymodules/python2.7/matplotlib/pyplot.pyc in savefig(*args, **kwargs)
    469 def savefig(*args, **kwargs):
    470     fig = gcf()
--> 471     return fig.savefig(*args, **kwargs)
    472 
    473 @docstring.copy_dedent(Figure.ginput)

/usr/lib/pymodules/python2.7/matplotlib/figure.pyc in savefig(self, *args, **kwargs)
   1183             kwargs.setdefault('edgecolor', rcParams['savefig.edgecolor'])
   1184 
-> 1185         self.canvas.print_figure(*args, **kwargs)
   1186 
   1187         if transparent:

TypeError: print_figure() got multiple values for keyword argument 'dpi'